﻿@model PNProject.Models.CommentModels
<div class="baidanhgia">
    @Html.Partial("DetailCommentContent",@Model)
    @* @if (Model.Comments != null && Model.Comments.Any())
    {
                        
        <p>Hiển thị 1-3 của 30 bình luận</p>
                           
        foreach (var comment in Model.Comments)
        {
        <div class="boxdanhgia">
            <div class="tentv">
                <ul>
                    <li>
                        @if (string.IsNullOrEmpty(comment.Username))
                        {
                            <p>Guess</p>
                        }
                        else
                        {
                            <p>comment.Username</p>
                        }

                        @if (@comment.SentDate != null && @comment.SentDate.HasValue)
                        {
                            <span>
                                @comment.SentDate.Value.ToString("dd.MM.dd")
                            </span>
                        }

                    </li>
                </ul>
            </div>
            <div class="danhgia-y">
                @if (!string.IsNullOrEmpty(comment.Message))
                {
                    <span>
                        @Html.Raw(comment.Message)

                    </span>
                }

            </div>
        </div>
        }



    }*@
</div>
<div class="pageT">
    <ul id="commentP">
        @if (Model.TotalPageComment == 1)
        {
            <li><a href="javascript:void(0)">1</a></li>
        }
        else if (1 < Model.TotalPageComment && Model.TotalPageComment <= 4)
        {
            for (int i = 1; i <= Model.TotalPageComment; i++)
            {
                var url = @Url.Action("PagingComments", "ProductDetails", new {id = @Model.ProductId, pageIndex = @i, pageSize = 3, AllowComment = Model.AllowComment});
                <li class="active"> <a id="@i" href="@url" onclick="GotoPage(this);return false;">@i</a> </li>
            }
        }
        else
        {
            var url = @Url.Action("PagingComments", "ProductDetails", new { id = @Model.ProductId, pageIndex = 1, pageSize = 3, AllowComment = Model.AllowComment });
             
            <li><a id="0" href="@url" onclick="GotoPage(this);return false;">Trang đầu</a></li>
            for (int i = 1; i <= Model.TotalPageComment; i++)
            {
                var url1 = @Url.Action("PagingComments", "ProductDetails", new { id = @Model.ProductId, pageIndex = @i, pageSize = 3, AllowComment = Model.AllowComment });
              
            <li class="active"> <a id="@i" href="@url1" onclick="GotoPage(this);return false;">@i</a> </li>
            }
            var url2 = @Url.Action("PagingComments", "ProductDetails", new { id = @Model.ProductId, pageIndex = Model.TotalPageComment, pageSize = 3, AllowComment = Model.AllowComment });
            <li><a id="@Model.TotalPageComment" href="@url2" onclick="GotoPage(this);return false;">Trang cuối</a></li>
        }


    </ul>
</div>
<div>
    @if (Model.AllowComment)
    {
        <div class="vietdanhgia">
            <p>Bình luận sản phẩm</p>
            <br />
            <br />
            <input type="text" placeholder="Email" style="height: 25px; width: 712px; border: 1px solid #FF7200" />
            <div class="comment">
                <textarea placeholder="Nội dung bình luận..." id="commentContent" maxlength="1000" rows="" cols="" name="comment" style="width: 712px; height: 70px; float: left; border: 1px solid #FF7200;"></textarea>
                <input type="submit" value="Gửi đi" name="submit" class="ui-button" id="sumbitComment" style="background: #ddd; border: none; color: #333; font-weight: bold; padding: 5px 20px; float: right; margin: 5px 0px 0px 0px; cursor: pointer;" />
            </div>

        </div>
    }
</div>
<script type="text/javascript">
    function GotoPage(seft) {
        var id = seft.id;
        $("#commentP li").addClass("active");
        if (id == 0) {
            $("#" + 1).parent().removeClass("active");
        } else {
            $("#" + id).parent().removeClass("active");
        }
        var href = $("#" + id).attr("href");
        $.ajax({
            cache: false,
            type: "POST",
            dataType: 'html',
            contentType: 'application/json',
            url: href,
            success: function (result) {
                $(".baidanhgia").html(result);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    //alert(thrownError);
                }
        });
        return false;
    }
</script>